package com.medicine.hbp.adapter;

import java.util.List;

import com.medicine.hbp.mob.InterestListVo;
import com.medicine.hbp.R;

import android.app.Activity;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.FrameLayout.LayoutParams;
import android.widget.ImageView;
import android.widget.TextView;

public class InterestOneAdapter extends BaseAdapter {
	private Activity activity;
	private List<InterestListVo> info;
	private boolean isDelete = false;
	private Handler handler;
	public InterestOneAdapter(Activity activity, List<InterestListVo> info,Handler handler) {
		this.activity = activity;
		this.info = info;
		this.handler = handler;
	}

	@Override
	public int getCount() {
		return info.size();
	}

	public Boolean getisDelete () {
		return isDelete;
	}
	public void setDelete(boolean isDelete) {
		this.isDelete = isDelete;
		notifyDataSetChanged();
	}

	public void setInfo(List<InterestListVo> info) {
		this.info = info;
		notifyDataSetChanged();
	}
	public String getListId(){
		String id = "";
		for (int i = 0; i < info.size(); i++) {
			id+=info.get(i).appTypeId+",";
		}
		if(id.length()>0){
			return id.substring(0,id.length()-1);
		}else{
			return null;
		}
		
	}
	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(final int arg0, View view, ViewGroup arg2) {
		viewHolder holder = null;
		if (view == null) {
			holder = new viewHolder();
			view = LayoutInflater.from(activity).inflate(R.layout.item_interest, null);
			holder.text = (TextView) view.findViewById(R.id.txt);
			holder.ImgExit = (ImageView) view.findViewById(R.id.img_exit);
			view.setTag(holder);
		} else {
			holder = (viewHolder) view.getTag();
		}
		String name = info.get(arg0).appTypeName;
		if (!TextUtils.isEmpty(name)) {
			holder.text.setText(name);
		}
		if (isDelete) {
			holder.ImgExit.setVisibility(View.VISIBLE);
		} else {
			holder.ImgExit.setVisibility(View.INVISIBLE);
		}
		holder.ImgExit.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Message message=new Message();
				message.arg1=arg0;
				handler.sendMessage(message);
			}
		});
		return view;
	}

	class viewHolder {
		TextView text;
		ImageView ImgExit;
	}

}
